<?php

class Invitation_Db_Table_Row_Observable extends Zend_Db_Table_Row_Abstract {
	
	protected static $_observers = array();
	
	public static function attachObserver($class) {
		if (!is_string($class) || !class_exists($class) || !is_callable(array($class, 'observeTableRow'))) {
			return false;
		}
		
		if (!isset(self::$_observers[$class])) {
			self::$_observers[$class] = true;
		}
		return true;
	}
	
	protected function _notifyObservers($event) {
		if (!empty(self::$_observers)) {
			foreach(array_keys(self::$_observers) as $observer) {
				call_user_func(array($observer, 'oberserveTableRow'), $event, $this);
			}
		}
		parent::_postInsert();
	}
	
	protected function _postInsert() {
		$this->_notifyObservers('post-insert');
	}
	
	/**
	 * Return searchable fields of invitation.
	 * 
	 * @param $invitation
	 * @return return searchable fields
	 */
	public function getSearchIndexFields($invitation) {
		$fields = array();
		$fields['class'] = 'Invitation';
		$fields['key'] = $invitation->id;
		$fields['title'] = $invitation->title;
		$fields['description'] = $invitation->description;
		return $fields;
	}
}
?>